package com.sise.aio和bio和nio.nio.零拷贝;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

/**
 * @author idea
 * @data 2019/4/9
 */
public class NioZeroCopyDemo {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();
        InetSocketAddress inetSocketAddress = new InetSocketAddress(9999);
        socketChannel.connect(inetSocketAddress);

        RandomAccessFile file =
                new RandomAccessFile(new File("D:\\project\\test"), "rw");
        FileChannel fileChannel = file.getChannel();
        fileChannel.transferTo(0, fileChannel.size(), socketChannel);
        fileChannel.close();
        file.close();
        socketChannel.close();

    }
}
